<?php
	session_start();
	$captcha="";
	
	for($i=0;$i<4;$i++){
		$captcha.=dechex(rand(1,15));
	}
	
	//Save captcha into session
	$_SESSION['captcha']=$captcha;
	
	//Create image
	$img=imagecreatetruecolor(80,22);
	
	//Backgroud color
	$bgcolor=imagecolorallocate($img,255,255,255);
	imagefill($img,0,0,$bgcolor);
	
	$black=imagecolorallocate($img,0,0,0);
	$blue=imagecolorallocate($img,0,0,255);
	$red=imagecolorallocate($img,255,0,0);
	$green=imagecolorallocate($img,0,255,0);
	
	imageline($img,0,0,0,22,$black);
	imageline($img,0,0,80,0,$black);
	imageline($img,79,21,79,0,$black);
	imageline($img,79,21,0,21,$black);
	
	//Draw random line
	for($i=0;$i<5;$i++){
		imageline($img,rand(0,70),rand(0,19),rand(0,70),rand(0,19),imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255)));
	}
		
	imagestring($img,rand(4,60),rand(0,9),rand(0,9),$captcha,$black);
	//Output
	header("content-type: image/png");
	imagepng($img);
	
	//Destroy image
	imagedestroy($img);
?>

